package com.itfenghuang.day07;


import java.util.*;

//HashMap Map的实现类
public class A05_HashMap {
    public static void main(String[] args) {
        /**
         * 1.概述
         *      底层使用哈希表实现
         *      键怎么保证唯一性   hashSet去重  依赖hashCode() 和 equals() 方法
         *
         * 2.案列
         *  向Hashmap集合中存储学生对象,key存储学生对象,国籍
         */

        HashMap<Student, String> map = new HashMap<>( );
        map.put(new Student("小波",18),"日本");
        map.put(new Student("小爱",18),"中国");
        map.put(new Student("Siri",8),"美国");
        map.put(new Student("Siri",8),"美国");
        System.out.println(map);

        System.out.println("=======增强for========");
        Set<Student> stu = map.keySet();
        for (Student student : stu) {
            String s = map.get(student);
            System.out.println(student+" "+s);
        }
        System.out.println("=======迭代器==========");
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        Iterator<Map.Entry<Student, String>> its = entries.iterator();
        while (its.hasNext()){
            Map.Entry<Student, String> next = its.next();
            String value = next.getValue();
            Student key = next.getKey();
            System.out.println(key+"="+value);
        }

    }
}
